import { Period } from "@/types/config"
import { ExpenseItemForInteraction, SiftedExpense } from "@/types/expense"
import request from "@/utils/request"

export function deleteExpense(id: number) {
    return request({
        method: 'delete',
        url: '/outcome/delete',
        params: { id }
    })
}

export function getOnePageExpense(siftExpense: SiftedExpense) {
    return request({
        method: 'get',
        url: '/outcome/page',
        params: siftExpense
    })
}

export function modifyExpense(expense: ExpenseItemForInteraction) {
    return request({
        method: 'put',
        url: '/outcome',
        data: expense
    })
}

export function addExpense(expense: ExpenseItemForInteraction) {
    return request({
        method: 'post',
        url: '/outcome/save',
        data: expense
    })
}

export function getDetailedExpense(period: Period) {
    return request({
        method: 'get',
        url: '/outcome/detailedOutcome',
        params: period
    })
}

export function getClassifiedExpense(period: Period) {
    return request({
        method: 'get',
        url: '/outcome/classifiedOutcome',
        params: period
    })
}

export function addExpenseType(typeName: String, typeKey: Number) {
    return request({
        method: 'post',
        url: '/second/save',
        data: {
            typeName, typeKey
        }
    })
}

export function getExpenseTypeList() {
    return request({
        method: 'get',
        url: '/second/select'
    })
}

export function deleteExpenseTypes(ids: Number[]) {
    return request({
        method: 'delete',
        url: 'second/delete',
        params: {
            ids: ids.join(',')
        }
    })
}